package com.example.test.主方法运行测试;


import com.baidu.aip.face.AipFace;
import com.baidu.aip.face.MatchRequest;
import com.example.test.util.ImageBase64;
import org.json.JSONObject;
import sun.misc.BASE64Encoder;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;

public class Sample {
    //设置APPID/AK/SK
    public static final String APP_ID = "17255172";
    public static final String API_KEY = "q5XlsyLqnKK5CQML0a4aRxWh";
    public static final String SECRET_KEY = "BZMa1GqkxxRHPnSAdGoCpKg1l2Qh1i26";

    public static void main(String[] args) {
        // 初始化一个AipFace
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 可选：设置代理服务器地址, http和socket二选一，或者均不设置
//        client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
//        client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理

        String path = "C:\\Users\\Administrator\\Desktop\\20167.jpg";


        // 调用接口
        String image = ImageBase64.getImageToBase64(path);
        String imageType = "BASE64";

        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "LOW");

        // 人脸检测
        JSONObject res = client.detect(image, imageType, options);
        System.out.println(res.toString(2));


            // 调用接口
        String image1 = ImageBase64.getImageToBase64(path);
        String image2 = ImageBase64.getImageToBase64(path);

        // image1/image2也可以为url或facetoken, 相应的imageType参数需要与之对应。
        MatchRequest req1 = new MatchRequest(image1, "BASE64");
        MatchRequest req2 = new MatchRequest(image2, "BASE64");
        ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>();
        requests.add(req1);
        requests.add(req2);

        JSONObject res1 = client.match(requests);
        System.out.println(res1.toString(2));


    }


}